package com.gitee.shop.service.impl;

import com.gitee.shop.domain.Item;
import com.gitee.shop.mapper.ItemMapper;
import com.gitee.shop.service.ItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ItemServiceImpl implements ItemService {
    @Autowired
    private ItemMapper itemMapper;
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return itemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Item record) {

        return itemMapper.insert(record);
    }

    @Override
    public Item selectByPrimaryKey(Integer id) {

        return itemMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Item> selectAll() {

        return itemMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(Item record) {

        return itemMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Item> selectByIflag(int iflag) {
        return itemMapper.selectByIflag(iflag);
    }

    //根据分类id查询商品信息
    /**
     *
     * @param cid 商品分类id
     * @param pageNum 页数
     * @param pageSize 单页面显示记录数
     * @return 返回分类信息对象
     */
    @Override
    public PageInfo<Item> selectPageByCid(int cid, int pageNum, int pageSize) {
        //开启分页
        PageHelper.startPage(pageNum,pageSize);
        //根据分类id查询商品
        List<Item> items = itemMapper.selectByCid(cid);
        //根据集合创建分类对象
        PageInfo<Item> pageInfo = new PageInfo<>(items);
        //返回分页信息对象
        return pageInfo;
    }
}
